package com.msb.dongbao.portal.web.controller.studyCaptcha;

import com.ramostear.captcha.HappyCaptcha;
import com.ramostear.captcha.support.CaptchaStyle;
import com.ramostear.captcha.support.CaptchaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: mayu
 * @date: 2021年05月28日 14:55
 */
@RestController
@RequestMapping("/happy-captcha")
public class HappyCaptchaController {
    String attrName = "verifyCode";

    @GetMapping("/generator")
    public void generatorCode(HttpServletRequest request, HttpServletResponse response) {
        HappyCaptcha.require(request, response)
                .style(CaptchaStyle.ANIM)
                .type(CaptchaType.ARITHMETIC_ZH)
                .build().finish();
    }


    @GetMapping("/verify")
    public String verify(String verifyCode, HttpServletRequest request) {
        boolean flag = HappyCaptcha.verification(request, verifyCode, true);
        if (flag) {
            HappyCaptcha.remove(request);
            return "通过";
        }
        return "不通过";
    }
}
